package com.wangyadong.hobby.schedule.jobtask.jvm.OOM;

import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONArray;
import com.alibaba.fastjson.JSONObject;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.stream.IntStream;

/**
 * <p>
 *
 * @author <714037465@qq.com>
 * @since 2018/11/2017:33
 **/
public class OOMObjectExample {

    static class OOMObject {
        public byte[] placeholder = new byte[64 * 1024];
    }


    public static void fillHeap(int num) throws InterruptedException {
        List<OOMObject> list = new ArrayList<>();
        for (int i = 0; i < num; i++) {
            Thread.sleep(50);
            list.add(new OOMObject());
        }
    }

    public static void main(String[] args) throws InterruptedException {
        fillHeap(200000000);
        String s="";
        System.out.println(Integer.toHexString(106));
//        Map<String, String> map = new HashMap();
//        map.put("aa", "222");
//        map.put("bb", "222");
//        map.put("cc", "222");
//        Map<String, Object> map1 = new HashMap();
//        map1.put("11", "qq");
//        map1.put("22", "");
//        map1.put("33", "ee");
//        System.out.println(installJson(map, map1, "3"));
//        System.out.println(JSON.toJSON(installJson(map, map1, "3")));

    }
    //insert type
    //[{"before":{"aa":"222","bb":"222","cc":"222"},"operateStatus":"1"}]

    private static String installJson(Object before, Object after, String status) {
        JSONObject jsonstatus = new JSONObject();
        jsonstatus.put("operateStatus", status);
        jsonstatus.put("before", before == null ? "" : before);
        jsonstatus.put("after", after == null ? "" : after);
        JSONArray total = new JSONArray();
        total.add(jsonstatus);
        return total.toString();
    }
}
